/**
 * 产品修改js
 */
var comValidform=null;
var returnStatus=false;
var productInfoUpdate={
	dataCache:null,
	proFeatureUE:null,
	proEnsureUE:null,
	coverCaseUE:null,
	coverFlowUE:null,
		
	startEvent:function(){
		$("#recordTab ul").idTabs();
		productInfoUpdate.proFeatureUE = UE.getEditor('proFeature',{
			initialFrameHeight:340,
			initialFrameWidth:898
		});
		productInfoUpdate.proEnsureUE = UE.getEditor('proEnsure',{
			initialFrameHeight:340,
			initialFrameWidth:898
		});
		productInfoUpdate.coverCaseUE = UE.getEditor('coverCase',{
			initialFrameHeight:340,
			initialFrameWidth:898
		});
		productInfoUpdate.coverFlowUE = UE.getEditor('coverFlow',{
			initialFrameHeight:340,
			initialFrameWidth:898
		});
		
		productInfoUpdate.showInfoById();
		
		comValidform=$(".com-addForm").Validform({
			datatype:{
				"m0-2" : /^[0-9]+(.[0-9]{1,2})?$/
			},
			tiptype:2,
			tipSweep:true,
			beforeSubmit:function(curform){
				var url = 'mgr/OverseaSafeInfoCtrl/updateOverseaSafeInfo';
				var params = jsUtils.serializeJson($('.com-addForm'));
				
				var proFeature=productInfoUpdate.proFeatureUE.getContent();
				params.proFeatureTxt=proFeature;
				delete params.proFeature;
				
				var proEnsure=productInfoUpdate.proEnsureUE.getContent();
				params.proEnsureTxt=proEnsure;
				delete params.proEnsure;
				
				var coverCase=productInfoUpdate.coverCaseUE.getContent();
				params.coverCaseTxt=coverCase;
				delete params.coverCase;
				
				var coverFlow=productInfoUpdate.coverFlowUE.getContent();
				params.coverFlowTxt=coverFlow;
				delete params.coverFlow;
				
				var cb = function(data){
					alert(data.msg);
					//成功返回
					if(data.resultCode==200){
						//关闭窗口并刷新数据
						art.dialog.close();
						returnStatus=true;
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return false;
			}
		});
	},
	
	showInfoById:function(){
		var updId=art.dialog.data('updId');  //修改id
		var url = 'mgr/OverseaSafeInfoCtrl/getOverseaSafeInfoById';
		var params ={
				'id':updId
		};
		var cb = function(data){
			if(data.resultCode==200){
				var ret=data.result;
				for(var i in ret){
					var text=ret[i];
					
					if(i=='hotSale'||i=='safeCompany'||i=='contributionsTime'||i=='prodType'||i=='tbAge'||i=='gkCoin'||i=='firstGktype'||i=='againGktype'||i=='proStatus'){
						$('#com-addForm select[name="'+i+'"]').val(text);
						continue;
					}else if(i=='comProblem'){
						$('#com-addForm textarea[name="'+i+'"]').val(text);
						continue;
					}else if(i=='proPic'){
						if(text!=''&&text!=null){
							$('#com-addForm input[name="'+i+'"]').val(text);
							text='<a href="'+SERVER_PATH+'photo/'+text+'" target="_blank">'+text+'</a>';
						}else{
							text='';
							$('#com-addForm input[name="'+i+'"]').val(text);
						}
						$('#filePath').html(text);
						continue;
					}
					$('#com-addForm input[name="'+i+'"]').val(text);
				}
				if(ret.proFeatureTxt!=null){
					productInfoUpdate.proFeatureUE.ready(function() {
						productInfoUpdate.proFeatureUE.setContent(ret.proFeatureTxt);
	                });
				}
				if(ret.proEnsureTxt!=null){
					productInfoUpdate.proEnsureUE.ready(function() {
						productInfoUpdate.proEnsureUE.setContent(ret.proEnsureTxt);
	                });
				}
				if(ret.coverCaseTxt!=null){
					productInfoUpdate.coverCaseUE.ready(function() {
						productInfoUpdate.coverCaseUE.setContent(ret.coverCaseTxt);
	                });
				}
				if(ret.coverFlowTxt!=null){
					productInfoUpdate.coverFlowUE.ready(function() {
						productInfoUpdate.coverFlowUE.setContent(ret.coverFlowTxt);
	                });
				}
			}
		};
		sendApiNoLoadSync(url, params, cb, 'POST');
	},
	
	bindEvent:function(){
		//上传照片
		$('#imageInfo').uploadify({
			'formData' : {
				'id':$('#proId').val()
			},
			'fileTypeDesc' : 'Images',
			'fileTypeExts' : '*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tiff',
			'sizeLimit' : 5000000,//控制上传文件的大小，单位byte服务器默认只支持30MB(30000000)，修改服务器设置请查看相关资料
			'queueID' : 'queue',
			'swf' : APP_ADDRESS+'js/uploadify/uploadify.swf',
			'uploader' : APP_ADDRESS+'mgr/OverseaSafeInfoCtrl/uploadPic',
			'buttonText' : '上传产品图片',
			'onUploadSuccess' : function(file, data,response) {
				console.log(data);
				var dataObj = JSON.parse(data);
				if (dataObj) {
					if (dataObj.resultCode == "200") {
						var pic='<a href="'+SERVER_PATH+'photo/'+dataObj.result.proPic+'" target="_blank">'+dataObj.result.proPic+'</a>';
						$('.com-addForm input[name="proPic"]').val(dataObj.result.proPic);
						$('#filePath').html(pic);
					} else {
						alert(dataObj.msg);
					}
				}
			}
		});
	},
	
	init:function(){
		productInfoUpdate.startEvent();
		productInfoUpdate.bindEvent();
	}
}
$(document).ready(function() {
	productInfoUpdate.init();
});
function submitForm(){
	comValidform.submitForm();
	return returnStatus;
}